<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>王者荣耀竞猜管理平台</title>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/static/jquery-easyui-1.5.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/static/jquery-easyui-1.5.3/themes/icon.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/kindeditor/themes/default/default.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/kindeditor/plugins/code/prettify.css"/>

    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/jquery-easyui-1.5.3/jquery.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/jquery-easyui-1.5.3/jquery.easyui.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/jquery-easyui-1.5.3/locale/easyui-lang-zh_CN.js"></script>
    <script charset="utf-8" src="${pageContext.request.contextPath}/static/kindeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="${pageContext.request.contextPath}/static/kindeditor/lang/zh-CN.js"></script>
    <script charset="utf-8"
            src="${pageContext.request.contextPath}/static/kindeditor/plugins/code/prettify.js"></script>
</head>
<body>
<div align="center">
    <form id="ff" method="post" action="/webSiteSetting/update" enctype="multipart/form-data">
        <input type="hidden" name="fdId" value="${webSiteSetting.fdId}">
        <table cellpadding="5">
            <tr>
                <td>公告标题：</td>
                <td><input class="easyui-textbox" type="text" id="fdTitle" name="fdTitle"
                           value="${webSiteSetting.fdTitle}"
                           data-options="required:true"/></td>
            </tr>
            <tr>
                <td>公告内容：</td>
                <td><input id="fdContent" type="hidden" name="fdContent">
                    <textarea id="content" name="content" cols="100" rows="12"
                              style="width:650px;height:270px;"></textarea>
                    <div style="display: none" id="temp">${webSiteSetting.fdContent}</div>
                </td>
            </tr>
            <tr>
                <td>标题颜色：</td>
                <td><input type="color" id="fdColor" name="fdColor" value="${webSiteSetting.fdColor}"/></td>
            </tr>
            <tr>
                <td>公告类型：</td>
                <td>
                    <input type="radio" name="fdType" value="0" ${webSiteSetting.fdType == 0 ?'checked':''} />系统公告
                    <input type="radio" name="fdType" value="1" ${webSiteSetting.fdType == 1 ?'checked':''}/>活动公告
                    <input type="radio" name="fdType" value="2" ${webSiteSetting.fdType == 2 ?'checked':''}/>新闻资讯
                </td>
            </tr>
            <tr>
                <td>顶部背景图：</td>
                <td>
                    <c:choose>
                        <c:when test="${webSiteSetting.fdBgPic != null && webSiteSetting.fdBgPic != ''}">
                            <img src="${webSiteSetting.fdBgPic}" width="100px" height="100px"><br>
                            <input class="easyui-filebox" name="bg" id="bg"
                                   data-options="prompt:'选择图片...',buttonText:'选择背景',accept: 'image/*',buttonAlign:'right',editable:false">
                        </c:when>
                        <c:otherwise>
                            <input class="easyui-filebox" name="bg" id="bg"
                                   data-options="prompt:'选择图片...',buttonText:'选择背景',accept: 'image/*',buttonAlign:'right',editable:false">
                        </c:otherwise>
                    </c:choose>
                </td>
            </tr>

            <tr>
                <td>是否启用：</td>
                <td>
                    <input type="radio" name="fdIsEnable" value="1" ${webSiteSetting.fdIsEnable == 1 ?'checked':''} />是
                    <input type="radio" name="fdIsEnable" value="0" ${webSiteSetting.fdIsEnable == 0 ?'checked':''} />否
                </td>
            </tr>
            <tr>
                <td>排序：</td>
                <td><input class="easyui-textbox" type="text" id="fdOrder" name="fdOrder"
                           value="${webSiteSetting.fdOrder}"
                           data-options="required:true"/></td>
            </tr>
        </table>
    </form>
    <div style="text-align:center;padding:5px">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">提交</a>
        <a href="javascript:void(0)" style="margin-left: 20px" class="easyui-linkbutton" onclick="clearForm()">重置</a>
    </div>
</div>
</body>
<script>
    var editor;
    KindEditor.ready(function (K) {
        editor = K.create('textarea[name="content"]', {
            cssPath: '/static/kindeditor/plugins/code/prettify.css',
            uploadJson: '/static/kindeditor/jsp/upload_json.jsp',
            fileManagerJson: '/static/kindeditor/jsp/file_manager_json.jsp',
            allowFileManager: true,
            afterCreate: function () {
                var self = this;
                K.ctrl(document, 13, function () {
                    self.sync();
                });
                K.ctrl(self.edit.doc, 13, function () {
                    self.sync();
                });
            }
        });
        prettyPrint();
        var content = $("#temp").html();
        console.log(content);
        editor.html(content);
    });

    function submitForm() {
        var html = editor.html();
        $("#fdContent").val(html);
        $('#ff').form('submit', {
            onSubmit: function () {
                return $(this).form('enableValidation').form('validate');
            },
            success: function (data) {
                var r = JSON.parse(data);
                if (r.code == 0) {
                    $.messager.alert("提示", r.msg, "info");
                    parent.closeWin();
                    parent.reLoad();
                    parent.clearSelections();
                } else {
                    $.messager.alert("提示", r.msg, "Warning")
                }
            }
        });
    }

    function clearForm() {
        $('#ff').form('clear');
    }
</script>
</html>
